unit ufrmDialogoPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ufrmMdiChildPadrao, StdCtrls, Buttons, DB;

type
  TfrmDialogoPadrao = class(TfrmMdiChildPadrao)
    btnGravar: TBitBtn;
    btnCancelar: TBitBtn;
    dsEditar: TDataSource;
    procedure btnCancelarClick(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure cancelar;
  end;

var
  frmDialogoPadrao: TfrmDialogoPadrao;

implementation

{$R *.dfm}

{ TfrmDialogoPadrao }

procedure TfrmDialogoPadrao.cancelar;
begin
  if (dsEditar.DataSet <> nil) and (dsEditar.DataSet.State <> dsBrowse) then
    dsEditar.DataSet.Cancel;
  Retornar(mrCancel);
  Close;
end;

procedure TfrmDialogoPadrao.btnCancelarClick(Sender: TObject);
begin
  inherited;
  Cancelar;
end;

procedure TfrmDialogoPadrao.btnGravarClick(Sender: TObject);
begin
  inherited;
  if (dsEditar.DataSet <> nil) and (dsEditar.DataSet.State in [dsInsert, dsEdit]) then
  begin
    dsEditar.DataSet.Post;
    dsEditar.DataSet.Refresh;
  end;
  Retornar(mrOk);
  Close;
end;

end.
